<?php

/**
 * 微信模板信息发送驱动类
 */
/**
 * 发送模板消息
 * @param array $data 消息结构
 * ｛
		"touser":"OPENID",
		"template_id":"2ix4NQJGCqIQ-hbj9M-jHPbaIH624Iy4tG1ky2B0Tbk",
		"url":"http://weixin.qq.com/download",
		"topcolor":"#FF0000",
		"data":{
			"first": {
				"value":"参数",
				"color":"#173177"	 //参数颜色
				},
			"content":{
				"value":"06月07日 19时24分",
				"color":"#173177"
				},
			"occurtime":{
				"value":"0426",
				"color":"#173177"
				},
			"remark":{
				"value":"消费",
				"color":"#173177"
				}
		}
	}
 * @return boolean|array
 */
class WXTempMsg extends Msg{	
	//引用微信类，调用发送方法发送文本信息
	public function sendMsg(){
		Vendor('Weixin.Weixin');
		$d['token']=getSysVal('token');
		$d['appid']=getSysVal('appid');
		$d['appsecret']=getSysVal('appsecret');
		$weixin=new WeixinChat($d);
		
		$data=[
			'touser'=>$this->touser,
			"template_id"=>"2ix4NQJGCqIQ-hbj9M-jHPbaIH624Iy4tG1ky2B0Tbk",
			"url"=>"http://weixin.qq.com/download",
			"topcolor"=>"#FF0000",
			"data"=>[
				"first"=>[
					"value"=>"参数",
					"color"=>"#173177"	
					],
				"content"=>[
					"value"=>$this->content,
					"color"=>"#173177"
				],
				"occurtime"=>[
					"value"=>time(),
					"color"=>"#173177"
				],
				"remark"=>[
					"value"=>"Yeah!",
					"color"=>"#173177"
				]
			]
		];
		$ret = $weixin -> sendTemplateMessage($data);
		if($ret){
			return true;
		}else{
			$this->error=$weixin->getError();
			return false;	
		}
	}
}